package com.yuan.weike.service.impl;

import com.yuan.weike.mapper.TaskEvaluationMapper;
import com.yuan.weike.model.TaskEvaluation;
import com.yuan.weike.service.TaskEvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TaskEvaluationServiceImpl implements TaskEvaluationService {

    @Autowired
    private TaskEvaluationMapper taskEvaluationMapper;

    @Override
    public TaskEvaluation addTaskEvaluation(TaskEvaluation taskEvaluation) {
        taskEvaluation.setCreatedTime(new Date());
        taskEvaluation.setUpdatedTime(new Date());
        taskEvaluationMapper.insert(taskEvaluation);
        return taskEvaluation;
    }

    @Override
    public TaskEvaluation getTaskEvaluationById(Long evaluationId) {
        return taskEvaluationMapper.selectById(evaluationId);
    }

    @Override
    public TaskEvaluation getTaskEvaluationByTaskId(Long taskId) {
        return taskEvaluationMapper.selectByTaskId(taskId);
    }

    @Override
    public List<TaskEvaluation> getAllTaskEvaluations() {
        return taskEvaluationMapper.selectAll();
    }

    @Override
    public List<TaskEvaluation> getTaskEvaluationsByTaskIds(List<Long> taskIds) {
        if (taskIds == null || taskIds.isEmpty()) {
            return List.of();
        }
        return taskEvaluationMapper.selectByTaskIds(taskIds);
    }

    @Override
    public TaskEvaluation updateTaskEvaluation(TaskEvaluation taskEvaluation) {
        taskEvaluation.setUpdatedTime(new Date());
        taskEvaluationMapper.update(taskEvaluation);
        return taskEvaluation;
    }

    @Override
    public boolean deleteTaskEvaluation(Long evaluationId) {
        return taskEvaluationMapper.deleteById(evaluationId) > 0;
    }
}